
<%@page contentType="text/html" pageEncoding="UTF-8" language="java" import="java.sql.*"%>



<% String uname= request.getParameter("username");
String pass = request.getParameter("password");
String email = request.getParameter("email") ;


String DRIVER = "com.mysql.jdbc.Driver";
Class.forName(DRIVER).newInstance();


Connection con=null;
ResultSet rs=null;
Statement stmt=null;

try{
String url="jdbc:mysql://localhost/CoTrans?user=cotrans&password=cotrans";

int i=1;
con=DriverManager.getConnection(url);
stmt=con.createStatement();
int a;

rs=stmt.executeQuery("select userName from UserInfo ");
boolean userExists = false;
while(rs.next()){
    if(rs.getString(1).equals(uname))
    {
        userExists = true;
        break;
    }
}
if(!userExists){
%>
0
<%
String sql ="insert into UserInfo (userName,password,email) values ('" +uname+ "','" +pass+ "','" +email+"')" ;
a = stmt.executeUpdate(sql);
}
else{
%>
1

<%}
rs.close();
stmt.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
%>
    
